package com.ease.util {
   import flash.utils.Proxy;
   import flash.utils.flash_proxy;

   import hessian.mxml.HessianService;

   use namespace flash_proxy;

   dynamic public class HessianRemoteService extends Proxy {
      private static var _services:Object = {};

      private var _service:HessianService = null;

      private var _secure:Boolean;

      public static function getInstance(destination:String):HessianRemoteService {
         var service:HessianRemoteService = _services[destination] as HessianRemoteService;
         if (service == null) {
            service = new HessianRemoteService(PrivateConstructorToken, destination);
            _services[destination] = service;
         }

         return service;
      }

      public function HessianRemoteService(token:Class, destination:String) {
         super();
         if (token != PrivateConstructorToken) {
            throw new Error("HessianRemoteService cannot be instantiated directly.");
         }

         _service = new HessianService();
         _service.destination = "hessian/" + destination;
      }

      override flash_proxy function callProperty(name:*, ...rest):* {
         try {
            return _service.getOperation(name).send.apply(this, rest);
         }
         catch (e:Error) {
         }
      }

      override flash_proxy function getProperty(name:*):* {
         return _service.getOperation(name);
      }
   }
}

class PrivateConstructorToken {}